<template>
    <div class="post-comment">
      <van-field
        v-model.trim="message"
        rows="2"
        autosize
        type="textarea"
        maxlength="20"
        placeholder="请输入留言"
        show-word-limit
      />
       <van-button size="mini" @click="onPost"
       :disable="!message">发布</van-button>
    </div>
</template>
<script>
import { addComment } from '@/api/comment'
export default {
   name:'PostComment',
   props:{
     target:{
       type:[Number,String,Object],
       required:true
     },
     articleId:{
       type:[Number,String,Object],
       required:null
     }
   },
   data() {
      return {
        message:''
      }
   },
   methods: {
     async onPost(){
       const res = await addComment({
         target:this.target.toString(),
         content:this.message,
         art_id:this.articleId ? this.articleId.toString() : null,
       })
       this.$emit('post-success',res.data.data.new_obj)
        this.$toast.success('发布成功')
        this.message=""
     }
   }
}
</script>
<style lang="scss" scoped>
.post-comment{
  padding:14px;
  display: flex;
  align-items: center;
}
</style>
